{% extends master.html %}
{% block head %}
<script type="text/javascript" src="/lib/string-format/0.5.0/string-format.min.js"></script>
<style>
.CodeMirror {
    width: 60rem;
}
</style>
{% end %}

{% block body %}
    <form method="POST" action="/task?option=save">
    <input name="oldName" style="display:none;" value="{{name}}"/>
    <div>
        <span style="padding-right:10px">标题</span><input id="name" name="name" value="{{name}}"></input>
    </div>
    <br/>
    <div>
        <button class="btn btn-primary mid-text">保存</button>
        <a class="btn btn-danger" href="javascript:deleteTask()">删除</a>
    </div>
    <br/>
    <textarea id="inputText" class="form-control" rows=30 name="content">{{content}}</textarea>
    </form>
<script>
    /*
    window.onload = function() {
        var inputText = document.getElementById("inputText");
        window.editor = CodeMirror.fromTextArea(inputText, {
            mode: "markdown",
            theme: "abcdef",
            lineNumbers: true,
            // lineWrapping: true,
        });
        // var rows = textContainer.innerHTML.count('\n');
        // editor.setOption("height", rows);
    }
    */

    function getTaskName () {
        return document.getElementById("name").value;
    }

    function deleteTask () {
        var name = getTaskName();
        var conf = confirm(format("删除【{}】?",name ));
        if (conf) {
            // ajax delete.
            // redirect
            ajaxGet("/task?option=del&name=" + name, function (responseText) {
                // body...
                if (responseText == "success") {
                    location.href="/task";
                } else {
                    alert("delete fail, result=" + responseText);
                }
            });
        }
    }
</script>
{% end %}